<!--
 * @name: 热门圈子
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-07-19 11:07:24
 * @LastEditors: 刘大可
 * @LastEditTime: 2023-10-20 10:02:56
-->
<template>
    <view>
       <!-- ss {{ JSON.stringify(authData)}} -->
        <view class="quan margin">
            <view class="flex tit">
                <image src="/static/icon/quan.png" mode="scaleToFill" />
                热门圈子
                <view class="all" @click="goQuan()" v-if="schoolInfo.article_cate&&schoolInfo.article_cate.length>0">更多+</view>
            </view>
        </view>
        <!-- {{schoolInfo}} -->
        <view class="quan_list flex margin-lr" v-if="schoolInfo.article_cate">
            <block v-if="schoolInfo.article_cate&&schoolInfo.article_cate.length>0">
                <block v-for="(item, index) in schoolInfo.article_cate" :key="index">
                    <view class="quan" v-if="index < 3"
                        @click="goArticle(('/gc_school/pages/article/list?class_id=' + item.class_id + '&class_name=' + item.class_name))">
                        <image :src="item.img" class="quan_img" />
                        <view class="tag">{{ item.class_name }}</view>
                    </view>
                </block>
            </block>
            <block v-else>
                <block v-for="(item, index) in article_cate" :key="index">
                    <view class="quan">
                        <image :src="item.img" class="quan_img" />
                        <view class="tag">{{ item.class_name }}</view>
                    </view>
                </block>
            </block>
        </view>

    </view>
</template>

<script>
var app = getApp();
export default {
    data() {
        return {
            sys:{},
            // schoolInfo:{},
            authData: { status: 0 },
        }
    },
    props: {
        // 即将弃用
        schoolInfo: {
            type: [Object, Array, String],
            default() {
                return {};
            }
        },
    },
    created() {
        
        if (uni.getStorageSync('token')) {
            this.getAuth()
        }
    },
    methods: {
        toList(type, id, auth, url, name) {

            var urls = '/gc_school/pages/article/list?class_id=' + id + '&class_name=' + name

            if (url) {
                uni.navigateTo({
                    url: url
                })
            }
            else {
                if (auth == 0) {
                    uni.navigateTo({
                        url: urls
                    })
                }
                //需要认证的分类
                else {
                    //没有认证过，提示去认证
                    if (this.authData.status == 0) {
                        uni.showModal({
                            title: '温馨提示',
                            content: '本内容只对本校认证学生查看，请先认证！',
                            success(res) {
                                if (res.confirm) {
                                    uni.navigateTo({
                                        url: '/gc_school/pages/user/student'
                                    })
                                } else {
                                    console.log('取消删除');
                                }
                            }
                        });
                    }
                    else {
                        //判断是否和当前一个学校
                        if (this.authData.data.s_id != uni.getStorageSync('schoolId')) {
                            uni.showToast({
                                title: '您好，本内容只对本校认证学生查看，您暂无权限。',
                                icon: 'none',
                                duration: 3000
                            })
                        }
                        else {
                            if (this.authData.data.state == 0) {
                                uni.showToast({
                                    title: '请等待审核结果',
                                    icon: 'none',
                                    duration: 3000
                                })
                            } else if (this.authData.data.state == 2) {
                                uni.navigateTo({
                                    url: '/gc_school/pages/user/student'
                                })
                            } else {
                                uni.navigateTo({
                                    url: urls
                                })
                            }
                        }
                    }
                }
            }

        },
        goQuan() {
            uni.redirectTo({
                url: '/gc_school/pages/article/index'
            })
        },
        getAuth() {
            var that = this;
            app.globalData.util.request({
                url: 'RenIndex/student',
                method: 'POST',
                data: {},
                success(res) {
                    that.authData = res.data.data
                    // if(res.data.data.msg == '您的账号已被禁用，请联系客服。'){
                    // 	uni.setStorageSync('userstate', '-1');
                    // }else{
                    // 	uni.setStorageSync('userstate', '1');
                    // }
                    // that.setData({
                    //     slideList: res.data.data.list
                    // });
                }
            }, true);
        },

        goArticle(url = "") {
            console.log(url);
            let class_id = url.split("class_id=")[1].split("&")[0]
            console.log(class_id);
            var that = this;
            app.globalData.util.request({
                url: 'ZhForumClass/view',
                method: 'POST',
                data: {
                    class_id
                },
                success(res) {
                    console.log(res);
                    let item = res.data.data
                    that.toList(1, item.class_id, item.is_auth_watch, item.url, item.class_name)
                }
            }, true);

        },

        toList(type, id, auth, url, name) {
            if (type == 1) {
                var urls = '/gc_school/pages/article/list?class_id=' + id + '&class_name=' + name
            }
            else {
                var urls = '/gc_school/pages/article/detail?id=' + id
            }
            console.log(name)
            console.log(auth);
            console.log(url);
          
            // else {
                if (auth == 0) {
                    if (url) {
                        uni.navigateTo({
                            url: url
                        })
                        return
                    }
                    uni.navigateTo({
                        url: urls
                    })
                }
                //需要认证的分类
                else {
                    //没有认证过，提示去认证
                    if (this.authData.status == 0) {
                        uni.showModal({
                            title: '温馨提示',
                            content: '本内容只对本校认证学生查看，请先认证！',
                            success(res) {
                                if (res.confirm) {
                                    uni.navigateTo({
                                        url: '/gc_school/pages/user/student'
                                    })
                                } else {
                                    console.log('取消删除');
                                }
                            }
                        });
                    }
                    else {
                        //判断是否和当前一个学校
                        if (this.authData.data.s_id != uni.getStorageSync('schoolId')) {
                            uni.showToast({
                                title: '您好，本内容只对本校认证学生查看，您暂无权限。',
                                icon: 'none',
                                duration: 3000
                            })
                        }
                        else {
                            if (this.authData.data.state == 0) {
                                uni.showToast({
                                    title: '请等待审核结果',
                                    icon: 'none',
                                    duration: 3000
                                })
                            } else if (this.authData.data.state == 2) {
                                uni.navigateTo({
                                    url: '/gc_school/pages/user/student'
                                })
                            } else {
                                uni.navigateTo({
                                    url: urls
                                })
                            }
                        }
                    }
                }
            // }、

        },
    }
}
</script>